﻿using NetCore.CustomAttributes;
using NetCore.Entities.Projects;
using NetCore.Enums;
using NetCore.ValueObjects;
using System.Collections.Generic;
using System.ComponentModel;
using System.ComponentModel.DataAnnotations;

namespace NetCore.Entities.Organizations
{
    /// <summary>
    /// 组织机构/岗位
    /// 设计：1、类型为岗位的组织有多个用户(学员) 用户(学员)有多个岗位
    ///       2、机构都有项目(课程)列表，项目(课程)只有一个机构
    /// 注：这里的岗位设计在机构层面，对岗位分配数据权限,所有表均有机构外键 过滤数据用
    ///     用户(学员)中有学员类型(级别)  这样设计是为了学员与公司员工共用User表
    /// 另：项目(课程)可包含多个用户(学员),用户(学员)可以参加多个项目(课程)
    /// </summary>
    [Description("组织机构/岗位")]
    public class Organization : BaseEntity
    {
        public Organization()
        {
            OrganizationUsers = new HashSet<OrganizationUser>();//也可使用HashSet/ICollection它继承了ICollection ICollection继承了IEnumerable接口
            Projects = new HashSet<Project>();//1对多关系
            Children = new HashSet<Organization>();//子级节点
        }
        /// <summary>
        /// 用户 多个用户
        /// </summary>
        [Description("用户"), NotSet]
        public virtual HashSet<OrganizationUser> OrganizationUsers { get; set; }
        /// <summary>
        /// 项目列表
        /// </summary>
        [Description("项目列表"), NotSet]
        public virtual HashSet<Project> Projects { get; set; }
        /// <summary>
        /// 子级机构
        /// </summary>
        [Description("子级机构"), NotSet]
        public virtual HashSet<Organization> Children { get; set; }
        /// <summary>
        /// 父级机构Id
        /// </summary>
        [Description("父级机构Id")]
        public int? ParentId { get; set; }
        /// <summary>
        /// 父级机构
        /// </summary>
        [Description("父级机构"), NotSet]
        public virtual Organization Parent { get; set; }
        /// <summary>
        /// 机构名称
        /// </summary>
        [Description("名称"), MaxLength(NetCoreConsts.MaxLength256)]
        public string Name { get; set; }
        /// <summary>
        /// 机构代码
        /// </summary>
        [Description("代码"), MaxLength(NetCoreConsts.MaxLength64)]
        public string Code { get; set; }
        /// <summary>
        /// 类型
        /// </summary>
        [Description("类型"), MaxLength(NetCoreConsts.MaxLength256)]
        public OrganizationType OrganizationType { get; set; }
        /// <summary>
        /// 节点层级
        /// </summary>
        [Description("层级")]
        public TreeNodeLevel Level { get; set; }

        /// <summary>
        /// 所属地区
        /// </summary>
        [Description("所属地区")]
        public Address Address { get; set; }
    }
}
